﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLPMT_BUS;
using QLPMT_DTO;

namespace my_project_qlpmt1
{
    public partial class Fr_PhanHeNguoiDung : Form
    {
        public Fr_PhanHeNguoiDung()
        {
            InitializeComponent();
        }
        public void LoadThongTin()
        {
            List<HePhanQuyen> list = new HePhanQuyenBUS().GetAll();
            cbb_maphanquyen.DataSource = list;
            cbb_maphanquyen.DisplayMember = "TenPhanQuyen";
            cbb_maphanquyen.ValueMember = "MaPhanQuyen";
            List<LogIn> list1 = new LogInBUS().GetAll();
            //cbb_nguoidung.Text = "Danh Sách người dùng";
            //cbb_nguoidung.DataSource = list1;

            //cbb_nguoidung.DisplayMember = "User";
            //cbb_nguoidung.ValueMember = "Pass";

            //
            DGV_danhsachnguoidung.DataSource = list1;
            dgvcbb_phanquyen.DataSource = list;
            DGV_danhsachnguoidung.Columns["Maphanquyen"].Visible = false;
            dgvcbb_phanquyen.DisplayMember = "TenPhanQuyen";
            dgvcbb_phanquyen.ValueMember = "Maphanquyen";
            dgvcbb_phanquyen.DataPropertyName = "Maphanquyen";

        }
        private void button3_Click(object sender, EventArgs e)
        {
            string ma = cbb_maphanquyen.SelectedValue.ToString();
            string ten = txt_nguoidung.Text;
            string pass = txt_pass.Text;
            if (new LogInBUS().Update(ten, pass, ma) == true)
            {
                MessageBox.Show("Phân quyền thành công !", "Thông báo");
                LoadThongTin();
            }
            else
            {
                MessageBox.Show("Phân quyền bị lỗi!", "Thông báo");
            }
        }

        private void DGV_danhsachnguoidung_MouseClick(object sender, MouseEventArgs e)
        {
            txt_nguoidung.Text = DGV_danhsachnguoidung.SelectedRows[0].Cells["u"].Value.ToString();
            txt_pass.Text = DGV_danhsachnguoidung.SelectedRows[0].Cells["p"].Value.ToString();
        }

        private void Fr_PhanHeNguoiDung_Load(object sender, EventArgs e)
        {
            LoadThongTin();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            new LogInBUS().delete(DGV_danhsachnguoidung.SelectedRows[0].Cells["u"].Value.ToString());
            LoadThongTin();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            new LogInBUS().Insert(txt_nguoidung.Text, txt_pass.Text, txt_pass.Text);
            LoadThongTin();
        }
    }
}
